<style>
</style>
<template>
  <list_url ref="list_url" :config="config">
    <template #action="{row}">
      <el-button @click="to_edit(row)" size="small">详情</el-button>
    </template>
  </list_url>
</template>
<script>
import {iframe, in_right_admin} from "@/js/tool.js";
import s94Mjs from "s94-js";
import {_config, decode_config} from "@/js/s94_tool.js";
import {ajax} from "@/js/api_tool.js";

export default {
  props: ['__iframe'],
  data(){
    let app = this, btns = {}, is_del = this.$get('is_del');

    let  status_config = this.admin_config('status_alias_map.agent_apply.status');
    let forms_config = {
     user_id: {label:'申请用户',name:'where[user_id][in]',config:'user/index',no_table:true,type:'list_id',value:''},
     status: {label:'状态',name:'where[status][eq]',type:'select_one',config:status_config,value:this.$get('status','')},
    };
    let list_cols = {
      id:{name:'id', label:'ID', width:'65px', fixed:'left', type: 'hidden'},
      user_info:{name:'user_info', label:'申请用户', width:'120px'},
      title:{name:'title', label:'代理商标题', width:'120px'},
      head_img:{name:'head_img', label:'头图', width:'120px',type:'file_img'},
      agent_category_ids:{name:'agent_category_ids', label:'代理类目', width:'120px',type:'select_more',config:[]},
      info:{name:'info', label:'简介'},
      status:{name:'status', label:'状态', width:'75px',type:'select_one',config:status_config},
      action_time:{name:'action_time', label:'审核时间', width:'165px'},
    };
    if (is_del){
      list_cols['delete_time'] = {name:'delete_time', label:'删除时间', width:'165px', type:'datetime'};
    }else {
      list_cols['create_time'] = {name:'create_time', label:'申请时间', width:'165px'};
    }
    list_cols['action'] = {name:'action', label:'操作', width:'80px', type:'action', fixed:'right'};

    return {
      config: {
        api: '/admin/agent_apply/'+(is_del?'recycle':'list'),
        title: "申请列表"+(is_del?'(已删除)':''),
        btns: btns,
        forms_config: forms_config,
        list_cols: list_cols,
        resdata: function(list){
          s94Mjs.each(list, function (v){
            v.user_info = v.nickname+'(ID='+v.user_id+')';
          })
          return list;
        },
        limit: 20,
        p: this.$get('p', 1),
      },
    }
  },
  methods: {
    to_edit(row){
      let can_edit = in_right_admin('AgentApply/edit') && ~[0,row.tenant_id].indexOf(_config('this_tenant.id'))
      let param = {
        id: row.id,
      }
      if (!can_edit) param['is_info'] = 1;
      iframe('agent_apply/edit?'+s94Mjs.param_encode(param))
    },
  },
  mounted() {
    let app = this;
    if (!this.__iframe) window['app'] = this;

    ajax({url:'/admin/category/list',cache:true},function(res){
      let category_config = decode_config(res.data.list, {content_key:'name', value_key:'id'});
      app.config.list_cols.agent_category_ids.config = category_config;
      return false;
    })
  }
}
</script>
